public class Table {
	Deck deck;
	Human[] humans;
	Bot[] bots;

	Table(short humans_ammount, short bots_ammount) {
		for (int i = 0; i < humans_ammount; i++) {
			humans[i] = new Human(); 
		}
		if (bots_ammount > 0) {
			for (int i = 0; i < bots_ammount; i++) {
				bots[i] = new Bot();
			}
		}
		deck = new Deck(); //tworzy i tasuje talie

		for (int i = 1; i <= 5; i++) {
			for (int h = 0; h < humans.length; h++) {
				humans[h].hand[i] = deck.drawFromDeck();
			}
			if (bots_ammount > 0) {
				for (int b = 0; b < bots.length; b++) {
					bots[b].hand[i] = deck.drawFromDeck();
				}
			}
		}

		for (int h = 0; h < humans.length; h++) {
			exchange(humans[h]);
		}
		if (bots_ammount > 0) {
			for (int b = 0; b < bots.length; b++) {
				exchange(bots[b]);
			}
		}
	}

	private void exchange(Bot b) {
		boolean[] tochange = b.changeCards();
		for (int i = 0; i < tochange.length; i++) {
			if (tochange[i]) {
				b.hand[i] = deck.drawFromDeck();
			}
		}
	}

	private void exchange(Human h) {
		boolean[] tochange = h.changeCards();
		for (int i = 0; i < tochange.length; i++) {
			if (tochange[i]) {
				h.hand[i] = deck.drawFromDeck();
			}
		}
	}

	public static void main(String[] args) {
		short humans_ammount, bots_ammount; 
		if ((args.length == 1) || (args.length == 2)) {
			try {
				humans_ammount = Short.parseShort(args[0]);
				bots_ammount = Short.parseShort(args[1]);
			
				if ((humans_ammount < 1) || (humans_ammount > 4))
					System.out.println("Blad! Podana liczba ludzi musi nalezec do przedzialu od 1 do 4.");
				else if ((bots_ammount < 0) || (bots_ammount > 3))
					System.out.println("Blad! Podana liczba botow musi nalezec do przedzialu od 0 do 3.");
				else if (((humans_ammount + bots_ammount) < 2) || ((humans_ammount + bots_ammount) > 4))
					System.out.println("Blad! Podana liczba graczy musi nalezec do przedzialu od 2 do 4.");
				else {
					Table table = new Table(humans_ammount, bots_ammount);
				}
			}
			catch (NumberFormatException ex) {
				System.out.println("Blad! Wprowadzona wartosc musi byc liczba naturalna.");
			}
		}
		else {
			System.out.println("Program nalezy odpalic z nastepujacymi parametrami:");
			System.out.println("<liczba_graczy_ludzi> <liczba_graczy_botow>");
		}
	}
}
